import 'package:flutter_riverpod/flutter_riverpod.dart';

/// 导航栏索引枚举
enum NavigationTab { home, square, time, my }

/// 导航状态类
class NavigationState {
  final NavigationTab currentTab;

  const NavigationState({this.currentTab = NavigationTab.home});

  NavigationState copyWith({NavigationTab? currentTab}) {
    return NavigationState(currentTab: currentTab ?? this.currentTab);
  }
}

/// 导航状态管理器
class NavigationNotifier extends StateNotifier<NavigationState> {
  NavigationNotifier() : super(const NavigationState());

  /// 切换到指定标签页
  void switchTab(NavigationTab tab) {
    state = state.copyWith(currentTab: tab);
  }

  /// 切换到指定索引的标签页
  void switchToIndex(int index) {
    final tab = NavigationTab.values.firstWhere(
      (tab) => tab.index == index,
      orElse: () => NavigationTab.home,
    );
    switchTab(tab);
  }
}

/// 导航状态 Provider
final navigationProvider =
    StateNotifierProvider<NavigationNotifier, NavigationState>(
      (ref) => NavigationNotifier(),
    );
